/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.vector.view;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.table.DefaultTableModel;

import org.vector.daoImpl.BookDaoImpl;
import org.vector.serviceImpl.BookServiceImpl;

/**
 *
 * @author 73786
 */
@SuppressWarnings("serial")
public class Winbookloo extends javax.swing.JFrame {
	BookDaoImpl bdi = new BookDaoImpl();
	String[][] date = null;
	String[][] date2 = null;
	BookServiceImpl bsi = new BookServiceImpl();

	/**
	 * Creates new form Winbookloo
	 */
	public Winbookloo() {
		initComponents();
		setVisible(true);
	}

	private void initComponents() {

		jTabbedPane2 = new javax.swing.JTabbedPane();
		jPanel1 = new javax.swing.JPanel();
		c1 = new javax.swing.JComboBox<>();
		a1 = new javax.swing.JTextField();
		jScrollPane1 = new javax.swing.JScrollPane();
		jTable1 = new javax.swing.JTable();
		jButton1 = new javax.swing.JButton();
		jButton2 = new javax.swing.JButton();
		jPanel2 = new javax.swing.JPanel();
		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jLabel3 = new javax.swing.JLabel();
		jLabel4 = new javax.swing.JLabel();
		jLabel5 = new javax.swing.JLabel();
		jLabel6 = new javax.swing.JLabel();
		jLabel7 = new javax.swing.JLabel();
		jLabel8 = new javax.swing.JLabel();
		q1 = new javax.swing.JTextField();
		q3 = new javax.swing.JTextField();
		q4 = new javax.swing.JTextField();
		q5 = new javax.swing.JTextField();
		q7 = new javax.swing.JTextField();
		q8 = new javax.swing.JTextField();
		q6 = new javax.swing.JTextField();
		jButton3 = new javax.swing.JButton();
		jButton4 = new javax.swing.JButton();
		q2 = new javax.swing.JTextField();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setTitle("图书信息查询");
		setBounds(300, 250, 671, 589);

		jTabbedPane2.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N

		c1.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		c1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "分类" }));

		jTable1.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		jTable1.setModel(new javax.swing.table.DefaultTableModel(bdi.getBook(),
				new String[] { "编号", "分类", "名称", "作者", "出版社", "出版日期", "出版社", "单价" }));
		jTable1.setRowHeight(30);
		jScrollPane1.setViewportView(jTable1);

		jButton1.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		jButton1.setText("查询");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});

		jButton2.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		jButton2.setText("退出");
		jButton2.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton2ActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
						.addComponent(c1, javax.swing.GroupLayout.PREFERRED_SIZE, 99,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(18, 18, 18)
						.addComponent(a1, javax.swing.GroupLayout.PREFERRED_SIZE, 362,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
						jPanel1Layout.createSequentialGroup().addContainerGap(41, Short.MAX_VALUE)
								.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 532,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addContainerGap(53, Short.MAX_VALUE))
				.addGroup(jPanel1Layout.createSequentialGroup().addGap(183, 183, 183)
						.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 108,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 107,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
		jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
						.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
								.addComponent(a1, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
								.addComponent(c1))
						.addGap(18, 18, 18)
						.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 337,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(35, 35, 35)
						.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 38,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 38,
										javax.swing.GroupLayout.PREFERRED_SIZE))
						.addContainerGap(27, Short.MAX_VALUE)));

		jTabbedPane2.addTab("图书信息查询", jPanel1);
		jPanel1.getAccessibleContext().setAccessibleName("tab1");

		jLabel1.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		jLabel1.setText("ISBN");

		jLabel2.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		jLabel2.setText("单价");

		jLabel3.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		jLabel3.setText("印刷次数");

		jLabel4.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		jLabel4.setText("出版日期");

		jLabel5.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		jLabel5.setText("出版社");

		jLabel6.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		jLabel6.setText("类别");

		jLabel7.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		jLabel7.setText("书名");

		jLabel8.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		jLabel8.setText("作者");

		q1.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N

		q3.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N

		q4.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N

		q5.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N

		q7.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N

		q8.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N

		q6.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N

		jButton3.setText("修改");
		jButton3.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton3ActionPerformed(evt);
			}
		});

		jButton4.setText("关闭");
		jButton4.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton4ActionPerformed(evt);
			}
		});

		q2.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N

		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
						.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(jPanel2Layout.createSequentialGroup().addGap(49, 49, 49)
								.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
										.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 64,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 64,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 64,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 64,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 64,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 85,
												javax.swing.GroupLayout.PREFERRED_SIZE)))
						.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
										.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 85,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 77,
												javax.swing.GroupLayout.PREFERRED_SIZE))))
						.addGap(30, 30, 30)
						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
								.addGroup(jPanel2Layout.createSequentialGroup().addGap(29, 29, 29)
										.addComponent(jButton3).addGap(34, 34, 34).addComponent(jButton4))
								.addGroup(jPanel2Layout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
										.addComponent(q1)
										.addComponent(q8, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
										.addComponent(q7, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
										.addComponent(q6, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
										.addComponent(q5, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
										.addComponent(q4, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
										.addComponent(q3, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
										.addComponent(q2)))
						.addContainerGap(116, Short.MAX_VALUE)));
		jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(jPanel2Layout.createSequentialGroup().addContainerGap(43, Short.MAX_VALUE)
						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(q1, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
								.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
										jPanel2Layout.createSequentialGroup()
												.addComponent(q2, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(q3, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE))
						.addGap(18, 18, 18)
						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(q4, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE))
						.addGap(18, 18, 18)
						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(q5, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE))
						.addGap(18, 18, 18)
						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(q6, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE))
						.addGap(18, 18, 18)
						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(q7, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE))
						.addGap(18, 18, 18)
						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(q8, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
										javax.swing.GroupLayout.PREFERRED_SIZE))
						.addGap(40, 40, 40)
						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
										javax.swing.GroupLayout.PREFERRED_SIZE))
						.addGap(55, 55, 55)));

		jTabbedPane2.addTab("图书信息修改", jPanel2);
		jPanel2.getAccessibleContext().setAccessibleName("");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout
						.createSequentialGroup().addContainerGap().addComponent(jTabbedPane2,
								javax.swing.GroupLayout.PREFERRED_SIZE, 631, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(26, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout
						.createSequentialGroup().addContainerGap().addComponent(jTabbedPane2,
								javax.swing.GroupLayout.PREFERRED_SIZE, 551, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(25, Short.MAX_VALUE)));

		jTabbedPane2.getAccessibleContext().setAccessibleName("12");
		jTable1.addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent arg0) {}
			@Override
			public void mousePressed(MouseEvent arg0) {}
			@Override
			public void mouseExited(MouseEvent arg0) {}
			@Override
			public void mouseEntered(MouseEvent arg0) {}
			@Override
			public void mouseClicked(MouseEvent arg0) {
				// 获取表格中被选中的行
				int row = jTable1.getSelectedRow();
				date = bdi.getBook();
				// 设置文本框的内容
				q1.setText(date[row][0]);
				q2.setText(date[row][1]);
				q3.setText(date[row][2]);
				q4.setText(date[row][3]);
				q5.setText(date[row][4]);
				q6.setText(date[row][5]);
				q7.setText(date[row][6]);
				q8.setText(date[row][7]);
			}
		});
		pack();
	}// </editor-fold>
	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
		// new WinTip("功能异常");
		date2 = bdi.getBookone(a1.getText());
		if (date2 == null) {
			new WinTip("未找到该种类，换一下试试");
		} else {
			DefaultTableModel dataModel = new DefaultTableModel(date2,
					new String[] { "编号", "分类", "名称", "作者", "出版社", "出版日期", "出版社", "单价" });
			jTable1.setModel(dataModel);
			jTable1.addMouseListener(new MouseListener() {
				@Override
				public void mouseReleased(MouseEvent arg0) {}
				@Override
				public void mousePressed(MouseEvent arg0) {}
				@Override
				public void mouseExited(MouseEvent arg0) {}
				@Override
				public void mouseEntered(MouseEvent arg0) {}
				@Override
				public void mouseClicked(MouseEvent arg0) {
					// 获取表格中被选中的行
					int row = jTable1.getSelectedRow();
					//date = bdi.getBook();
					// 设置文本框的内容
					q1.setText(date2[row][0]);
					q2.setText(date2[row][1]);
					q3.setText(date2[row][2]);
					q4.setText(date2[row][3]);
					q5.setText(date2[row][4]);
					q6.setText(date2[row][5]);
					q7.setText(date2[row][6]);
					q8.setText(date2[row][7]);
				}
			});
		}
		
	}

	private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
		Winbookloo.this.dispose();
	}

	private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
		int row = jTable1.getSelectedRow();
		date = bdi.getBook();
		String asd = date[row][0];

		String q = q1.getText();
		String w = q2.getText();
		String e = q3.getText();
		String s = q4.getText();
		String t = q5.getText();
		String y = q6.getText();
		String a = q7.getText();
		String d = q8.getText();

		int r = bsi.Booklook(asd, q, w, e, s, t, y, a, d);
		if (r == 1) {
			Winbookloo.this.dispose();
			new WinTip("修改成功");
			new Winbookloo();
		} else {
			new WinTip("修改失败");
		}

	}

	private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
		Winbookloo.this.dispose();
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		new Winbookloo();
	}

	// Variables declaration - do not modify
	private javax.swing.JTextField a1;
	private javax.swing.JComboBox<String> c1;
	private javax.swing.JButton jButton1;
	private javax.swing.JButton jButton2;
	private javax.swing.JButton jButton3;
	private javax.swing.JButton jButton4;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JLabel jLabel7;
	private javax.swing.JLabel jLabel8;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTabbedPane jTabbedPane2;
	private javax.swing.JTable jTable1;
	private javax.swing.JTextField q1;
	private javax.swing.JTextField q2;
	private javax.swing.JTextField q3;
	private javax.swing.JTextField q4;
	private javax.swing.JTextField q5;
	private javax.swing.JTextField q6;
	private javax.swing.JTextField q7;
	private javax.swing.JTextField q8;
	// End of variables declaration
}
